package common

import (
	"go-toy/util"

	"gopkg.in/natefinch/lumberjack.v2"
)

type Rolling struct {
}

func (r *Rolling) Build() *lumberjack.Logger {
	pathname := FileIntance.PathName()

	lumberJackLogger := &lumberjack.Logger{
		Filename:   pathname,                                    // log file path and name
		MaxSize:    util.Viper.GetInt("log.rolling.maxSize"),    // in MB
		MaxAge:     util.Viper.GetInt("log.rolling.maxAge"),     // in days
		MaxBackups: util.Viper.GetInt("log.rolling.maxBackups"), // number of backups
		Compress:   util.Viper.GetBool("log.rolling.compress"),  // compress the backup files
	}
	return lumberJackLogger
}

var RollingIntance = &Rolling{}
